%Figure S5
clear variables
load('FigS5_weather_bootstrapped.mat')

%% Figure S5 Panel A
figure
ax = usamap('all');
set(ax, 'Visible', 'off')
states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = []; 

for i=1:numel(states)-1 %fills everything leaving DC for last
    if i<9
        states(i).r=r_observed(i,2);
    else
        states(i).r=r_observed(i+1,2);
    end
end

states(51).r=r_observed(9,2);

%hatch marks
hatch=zeros(51,1);
for i=1:51
    if r_observed(i,2)+1.96*r_bs(i,2)>0 && r_observed(i,2)-1.96*r_bs(i,2)<0
        hatch(i)=1;
        if r_observed(i,2)+1.64*r_bs(i,2)>0 && r_observed(i,2)-1.64*r_bs(i,2)<0
            hatch(i)=2;
        end
    end
    
end

surfaceColors = makesymbolspec('Polygon', {'r', ...
    [-1 1], 'FaceColor', flipud(cmap) });

% Display the three regions.

geoshow(ax(1), states(indexConus),  'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(2), states(indexAlaska), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(3), states(indexHawaii), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
% Hide the frame.
% 
for i=find(hatch)'
    if i~= 2 && i~=12 
        if i<9
        tmp_hp=patchm(states(i).Lat,states(i).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            else 
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end
        else
        tmp_hp=patchm(states(i-1).Lat,states(i-1).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            else
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end       
        end
    end
end

if hatch(2)
    axes(ax(2))
    tmp_hp=patchm(states(2).Lat,states(2).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(2)==1
        hatchfill2(tmp_hp,'single','HatchAngle',30,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    else
        hatchfill2(tmp_hp,'cross','HatchAngle',30,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    end  
end

if hatch(12)
    axes(ax(3))
    tmp_hp=patchm(states(11).Lat,states(11).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(12)==1
        hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    else
        hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    end
end

axes(ax(1))
caxis([-1 1])
colormap(flipud(cmap))

colorbar

for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end

%% Figure S5 Panel B

figure
ax = usamap('all');
set(ax, 'Visible', 'off')
states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = []; 

for i=1:numel(states)-1 %fills everything leaving DC for last
    if i<9
        states(i).r=r_observed(i,1);
    else
        states(i).r=r_observed(i+1,1);
    end
end

states(51).r=r_observed(9,1);

%hatch marks
hatch=zeros(51,1);
for i=1:51
    if r_observed(i,1)+1.96*r_bs(i,1)>0 && r_observed(i,1)-1.96*r_bs(i,1)<0
        hatch(i)=1;
        if r_observed(i,1)+1.64*r_bs(i,1)>0 && r_observed(i,1)-1.64*r_bs(i,1)<0
            hatch(i)=2;
        end
    end
    
end

surfaceColors = makesymbolspec('Polygon', {'r', ...
    [-1 1], 'FaceColor', flipud(cmap) });

% Display the three regions.

geoshow(ax(1), states(indexConus),  'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(2), states(indexAlaska), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(3), states(indexHawaii), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
% Hide the frame.
% 
for i=find(hatch)'
    if i~= 2 && i~=12 
        if i<9
        tmp_hp=patchm(states(i).Lat,states(i).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            else 
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end
        else
        tmp_hp=patchm(states(i-1).Lat,states(i-1).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            else
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end       
        end
    end
end

if hatch(2)
    axes(ax(2))
    tmp_hp=patchm(states(2).Lat,states(2).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(2)==1
        hatchfill2(tmp_hp,'single','HatchAngle',30,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    else
        hatchfill2(tmp_hp,'cross','HatchAngle',30,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    end  
end

if hatch(12)
    axes(ax(3))
    tmp_hp=patchm(states(11).Lat,states(11).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(12)==1
        hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    else
        hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    end
end

axes(ax(1))
caxis([-1 1])
colormap(flipud(cmap))

colorbar

for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end